package com.netty.kkk.service;

import com.netty.kkk.mapper.ChatMapper;
import com.netty.kkk.vo.ChatInfo;
import com.netty.kkk.vo.MessageRecord;
import com.netty.kkk.vo.UserInfo;
import org.apache.tomcat.util.http.fileupload.util.LimitedInputStream;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.processing.Messager;
import java.util.ArrayList;
import java.util.List;

@Service
public class ChatService {
    @Autowired
    private ChatMapper chatMapper;

    public List<ChatInfo> getUserChatList(String username){
        List<ChatInfo> chatList = chatMapper.listChat(username);//获取用户的所有chatId(, 分隔)
        return chatList;
    }

    public ChatInfo getChatInfoById(String chatId){
        ChatInfo chatInfo = chatMapper.getChatInfoById(chatId);
        return chatInfo;
    }

    public List<UserInfo> getMemberById(String chatId){
        List<UserInfo> memberList = chatMapper.getMemberById(chatId);
        return memberList;
    }

    public void recordMsg(MessageRecord messageRecord){
        chatMapper.recordMsg(messageRecord);
    }

    public List<MessageRecord> getMsgRecorder(String groupId, int start, int num){
        List<MessageRecord> messageRecordList = chatMapper.getMsgRecorder(groupId, start, num);
        return messageRecordList;
    }

    public void deleteChat(String chatId){
        chatMapper.deleteChat(chatId);
    }

    public void quitChat(String chatId, String userId){
        chatMapper.quitChat(chatId, userId);
    }

    public void changeChatName(String chatId, String chatName){
        chatMapper.changeChatName(chatId, chatName);
    }

    public int createNewChat(ChatInfo chatInfo){
        return chatMapper.createNewChat(chatInfo);
    }

    public void insertMembers(int chatId, List<String> memberList){
        chatMapper.insertMembers(chatId, memberList);
    }
}
